package BuilderPattern.exercise7_2;

public class TextBuilder extends Builder {
    private StringBuffer buffer = new StringBuffer();

    @Override
    public void makeTitle(String title) {
        buffer.append("===================================\n");
        buffer.append("「").append(title).append("」\n");
        buffer.append("\n");
    }

    @Override
    public void makeString(String str) {
        buffer.append('♦').append(str).append("\n").append("\n");
    }

    @Override
    public void makeItems(String[] items) {
        for (String each : items
        ) {
            buffer.append("- ").append(each).append("\n");
        }
        buffer.append("\n");
    }

    @Override
    public void close() {
        buffer.append("===================================\n");
    }

    public String getResult() {
        //注意，HTMLBuilder和TextBuilder中的getResult不是抽象方法，而是独特的方法，所以可以返回自定义类型的值
        return buffer.toString();
    }
}
